/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * GUIMain.java
 *
 * Created on 20/06/2011, 13:21:38
 */
package GUILFTrabalhoFinal;

import LFTrabalhoFinal.Automato;
import java.awt.event.KeyEvent;

/**Graphic Unit Interface utilizada para entrada de dados pelo usuário, para teste
 * de aceitação de uma dada cadeia, pelo autômato representante da linguagem
 * L = {w | w não contém a subcadeia 000}. 
 * Esse autômato é representado pela expressão regular (1*0(1*|0)1*)*. 
 * Informações sobre o trabalho: 
 * Trabalho Final de Linguagens Formais, sendo o código a representação do
 * autômato da linguagem do tópico 27 apresentado no Moodle.
 *
 * @author Euler Guimarães Lobo
 * @since Release R1 da aplicação
 * @version 1.0
 */
public class GUIMain extends javax.swing.JFrame {

    /** Creates new form GUIMain */
    public GUIMain() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTextArea1 = new javax.swing.JTextArea();
        jLabel1 = new javax.swing.JLabel();
        jTextField1 = new javax.swing.JTextField();
        jButton1 = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTextArea2 = new javax.swing.JTextArea();
        jPanel3 = new javax.swing.JPanel();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        jButton5 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setResizable(false);

        jPanel1.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Descrição da Linguagem"));

        jTextArea1.setColumns(20);
        jTextArea1.setEditable(false);
        jTextArea1.setRows(5);
        jTextArea1.setText("Linguagem L = { w | w não contem\na subcadeia 000}\n\nER: (1*0(1*|0)1*)*\n\nAlfabeto: {0,1}\n\nDesenvolvimento: Euler G. Lobo");
        jScrollPane1.setViewportView(jTextArea1);

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 128, Short.MAX_VALUE)
                .addContainerGap())
        );

        jLabel1.setText("Cadeia");

        jTextField1.setText("Insira cadeia para teste");
        jTextField1.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                TextFieldEnterAction(evt);
            }
        });

        jButton1.setText("Verificar");
        jButton1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButtonVerificarCliqueMouse(evt);
            }
        });
        jButton1.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jButtonVerificarEnterAction(evt);
            }
        });

        jTextArea2.setColumns(20);
        jTextArea2.setEditable(false);
        jTextArea2.setRows(5);
        jScrollPane2.setViewportView(jTextArea2);

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("Exemplos de Cadeia"));

        jButton2.setText("0010010");
        jButton2.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton0010010MouseClique(evt);
            }
        });
        jButton2.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jButton0010010EnterAction(evt);
            }
        });

        jButton3.setText("1000110");
        jButton3.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton1000110MouseClique(evt);
            }
        });
        jButton3.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jButton1000110EnterAction(evt);
            }
        });

        jButton4.setText("101010101");
        jButton4.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton101010101MouseClique(evt);
            }
        });
        jButton4.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jButton101010101EnterAction(evt);
            }
        });

        jButton5.setText("01001001");
        jButton5.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton01001001MouseClique(evt);
            }
        });
        jButton5.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jButton01001001EnterAction(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(jButton4, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jButton3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jButton2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 110, Short.MAX_VALUE)
                    .addComponent(jButton5, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap(92, Short.MAX_VALUE))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addComponent(jButton2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton4)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton5)
                .addContainerGap(23, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(0, 12, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addGap(3, 3, 3)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                                .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 367, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jButton1)))))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 118, Short.MAX_VALUE)
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void TextFieldEnterAction(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_TextFieldEnterAction
        
        if(evt.getKeyCode() == KeyEvent.VK_ENTER){
            TesteAutomato(jTextField1.getText());
        }
    }//GEN-LAST:event_TextFieldEnterAction

    private void jButtonVerificarEnterAction(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jButtonVerificarEnterAction
        if(evt.getKeyCode() == KeyEvent.VK_ENTER){
            TesteAutomato(jTextField1.getText());
        }
    }//GEN-LAST:event_jButtonVerificarEnterAction

    private void jButtonVerificarCliqueMouse(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButtonVerificarCliqueMouse
        TesteAutomato(jTextField1.getText());
    }//GEN-LAST:event_jButtonVerificarCliqueMouse

    private void jButton0010010EnterAction(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jButton0010010EnterAction
        if(evt.getKeyCode() == KeyEvent.VK_ENTER){
            jTextField1.setText("0010010");
            TesteAutomato("0010010");
        }
    }//GEN-LAST:event_jButton0010010EnterAction

    private void jButton1000110EnterAction(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jButton1000110EnterAction
        if(evt.getKeyCode() == KeyEvent.VK_ENTER){
            jTextField1.setText("1000110");
            TesteAutomato("1000110");
        }
    }//GEN-LAST:event_jButton1000110EnterAction

    private void jButton101010101EnterAction(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jButton101010101EnterAction
        if(evt.getKeyCode() == KeyEvent.VK_ENTER){
            TesteAutomato("101010101");
        }
    }//GEN-LAST:event_jButton101010101EnterAction

    private void jButton01001001EnterAction(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jButton01001001EnterAction
        if(evt.getKeyCode() == KeyEvent.VK_ENTER){
            jTextField1.setText("01001001");
            TesteAutomato("01001001");
        }
    }//GEN-LAST:event_jButton01001001EnterAction

    private void jButton0010010MouseClique(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton0010010MouseClique
        jTextField1.setText("0010010");
        TesteAutomato("0010010");
    }//GEN-LAST:event_jButton0010010MouseClique

    private void jButton1000110MouseClique(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton1000110MouseClique
        jTextField1.setText("1000110");
        TesteAutomato("1000110");
    }//GEN-LAST:event_jButton1000110MouseClique

    private void jButton101010101MouseClique(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton101010101MouseClique
        jTextField1.setText("101010101");
        TesteAutomato("101010101");
    }//GEN-LAST:event_jButton101010101MouseClique

    private void jButton01001001MouseClique(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton01001001MouseClique
        jTextField1.setText("01001001");
        TesteAutomato("01001001");
    }//GEN-LAST:event_jButton01001001MouseClique

    /**Método de inicialização do GUI.
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new GUIMain().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTextArea jTextArea1;
    private javax.swing.JTextArea jTextArea2;
    private javax.swing.JTextField jTextField1;
    // End of variables declaration//GEN-END:variables

    private void TesteAutomato(String cadeia){
        
        Automato teste = new Automato(cadeia);
        if(!teste.getRejeita()){
            jTextArea2.setText("Cadeia: "+cadeia+"\nAceita pelo autômato");
        }else{
            jTextArea2.setText("Cadeia: "+cadeia+"\nNão aceita pelo autômato");
        }//Fim do laço if
    }//Fim do metodo TesteAutomato
}
